package org.example.controller;


import org.example.pojo.Pepper;
import org.example.pojo.Phone;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class Controller3 {

    @GetMapping("/20210405019")
    public String method1() {
        return "这是一个学号";
    }

    @GetMapping("/Phone")
    public String method2() {
        Phone phone = new Phone();
        phone.setModel("abcdefg");
        phone.setLength(11.03f);
        phone.setWidth(11.03f);
        return phone.toString();
    }

    @GetMapping("/PhoneP1")
    public String method3(@RequestParam("model") String model,
                          @RequestParam("length") float length,
                          @RequestParam("width") float width) {
        Phone phone = new Phone();
        phone.setModel(model);
        phone.setLength(length);
        phone.setWidth(width);
        return phone.toString();
    }

    @GetMapping("/PhoneP2/{model}/{length}/{width}")
    public String method4(@PathVariable("model") String model,
                          @PathVariable("length") float length,
                          @PathVariable("width") float
width) {
        Phone phone = new Phone();
        phone.setModel(model);
        phone.setLength(length);
        phone.setWidth(width);
        return phone.toString();
    }


    @PostMapping("/PhoneP3")
    public String method5(String model,
                          float length,
                          float width) {
        Phone phone = new Phone();
        phone.setModel(model);
        phone.setLength(length);
        phone.setWidth(width);
        return phone.toString();
    }


    @GetMapping(value = "/month/{pram}")
    public ModelAndView method6(Model model, @PathVariable("pram") int pram) {
        model.addAttribute("condition",pram);
        model.addAttribute("var",pram);
        ModelAndView thym3 = new ModelAndView("thym3");
        return thym3;
    }
    @PostMapping("/login")
    public String addr3(@RequestParam(value = "user") String user, @RequestParam(value = "passwd") String passwd)
    {
        if((user=="盘古"&&passwd=="000")||(user=="女娲"&&passwd=="123")||(user=="伏羲"&&passwd=="321")){
            return "登录成功!";
        }
        else {
            return "用户名密码错误";
        }

    }

}
